@import "../global/global";

@mixin button-background($dark, $light) {
  background-color: #{$light};
  background-image: linear-gradient(to top, #{$dark}, #{$light});
}

@mixin button-shadow-normal($color) {
  box-shadow: inset 0 -2px 0 -1px $color;
}

@mixin button-shadow-hover($color) {
  box-shadow: inset 0 0 0 1px $color;
}

@mixin button-shadow-active($color) {
  box-shadow: inset 0 2px 0 -1px $color;
}

.ring-button {
  @include ring-font(12px);
  @include button-background(#f0f0f0, #fff);

  color: $ring-text-color;
  text-decoration: none;

  display: inline-block;
  position: relative;
  z-index: 0;

  box-sizing: border-box;
  height: $ring-unit*3;
  line-height: $ring-unit*3;
  padding: 0 $ring-unit*2;
  margin: 0;
  outline: 0;

  border: 0;
  border-radius: $ring-border-radius;
  box-shadow: inset 0 1px 0 0 #ccc, inset 1px 0 0 0 #ccc, inset -1px 0 0 0 #ccc, inset 0 -1px 0 0 #bfbfbf;

  cursor: default;

  &:focus:not([disabled]):not(.ring-button_loader) {
    box-shadow: 0 0 0 2px rgba(37, 183, 255, 0.5) !important;
    z-index: 3;
  }

  &[disabled] {
    opacity: 0.5;
    pointer-events: none;
  }

  &:hover:not([disabled]):not(.ring-button_loader) {
    @include button-background(#e9e9e9, #fff);
    @include button-shadow-hover(#aaa);
    z-index: 1;
  }

  &:active:not([disabled]):not(.ring-button_loader),
  &.ring-button_active:not([disabled]):not(.ring-button_loader) {
    background: $ring-light-blue-color;
    box-shadow: inset 0 0 0 1px #25b7ff, inset 0 1px 4px 0 rgba(3, 116, 172, 0.5);
    z-index: 2;
  }

  &:active:focus:not([disabled]):not(.ring-button_loader),
  &.ring-button_active:focus:not([disabled]):not(.ring-button_loader) {
    box-shadow: 0 0 0 2px rgba(37, 183, 255, 0.5), inset 0 1px 2px 1px rgba(0, 0, 0, 0.1) !important;
  }

  .ring-icon {
    color: $ring-dark-gray-color;
    line-height: $ring-unit;
    vertical-align: 1px;
    top: auto;
  }

  sup {
    line-height: 0;
  }
}

.ring-button__icon.ring-button__icon {
  display: none;
}

.ring-button_icon .ring-button__icon.ring-button__icon {
  display: inline-block;
}

.ring-button::-moz-focus-inner {
  outline: 0;
  padding: 0;
  border: 0;
}

.ring-button_loader {
  pointer-events: none;

  &[disabled] {
    opacity: 1;
  }
}

.ring-button_primary {
  @include button-background(#ff5a00, #ff8543);
  @include button-shadow-normal(#cc4902);
  color: #fff;

  &:hover:not([disabled]):not(.ring-button_loader) {
    @include button-background(#ff5a00, #ff9f6b);
    @include button-shadow-hover(#cc4902);
  }

  &:active:not([disabled]):not(.ring-button_loader),
  &.ring-button_active:not([disabled]):not(.ring-button_loader) {
    @include button-background(#ff8543, #ff5a00);
    @include button-shadow-active(#cc4902);
  }

  .ring-icon {
    color: #fff;
  }
}

.ring-button_blue {
  @include button-background(#0084ff, #25b7ff);
  @include button-shadow-normal(#015099);
  color: #fff;

  &:hover:not([disabled]):not(.ring-button_loader) {
    @include button-background(#0084ff, #5bc9ff);
    @include button-shadow-hover(#0077e5);
  }

  &:active:not([disabled]):not(.ring-button_loader),
  &.ring-button_active:not([disabled]):not(.ring-button_loader) {
    @include button-background(#25b7ff, #0084ff);
    @include button-shadow-active(#0077e5);
  }

  .ring-icon {
    color: #fff;
  }
}

.ring-button_delayed {
  .ring-button__content {
    &:after {
      content: '…';
    }
  }
}

.ring-button_danger {
  color: $ring-error-color;

  .ring-icon {
    color: inherit;
  }
}

.ring-button_short {
  width: 4*$ring-unit;
  padding: 0;
}

@keyframes button-progress {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-4px);
  }
}

@keyframes button-loader-appear {
  0% {
    display: none;
    opacity: 0;
  }

  99% {
    display: block;
    opacity: 0;
  }

  100% {
    display: block;
    opacity: 1;
  }
}

.ring-button__loader {
  display: none;
  opacity: 0;

  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  margin-bottom: 0;
  max-width: none;
  background-color: transparent;
  overflow: hidden;

  &:after {
    content: '';
    bottom: 0;
    left: 0;
    position: absolute;
    right: -4px;
    top: 0;
    animation: button-progress 200ms linear infinite;
    background-repeat: repeat;
    background-image: url(./button-loader_white.svg);
  }

  .ring-button_loader & {
    display: block;
    opacity: 1;

    // TODO in CSS Modules version put constant to global.css
    animation: button-loader-appear 75ms linear 1;
  }

  .ring-button_loader.ring-button_default & {
    background-image: url(./button-loader_gray.svg);
  }
}
